<?php

//审核帖子
/**
 * @var $config
 * @var $key
 */
include 'api.php';
include '../WeSql/WeSql.php';
include '../WeSql/config.php';
include '../WeSql/widget.php';

/** @var 账号 $_REQUEST */
@$user = $_REQUEST['user'];
/** @var 密码 $_REQUEST */
@$pass = $_REQUEST['pass'];

@$fid = $_REQUEST['fid'];

$weSql = new WeSql($config);

if ($user == "" or $pass == "" or $fid == ""){
    $code = -1;
    $msg = "不能留空";
    $exception = "";
}else{
    if(decrypt($key,$weSql->select("user","user=${user}")['pass']) == $pass) {
        if($weSql->select("user","user=${user}")['admin'] > 0){
            //只有管理员与作者能够审核后

            if($weSql->isSelectField("forum",[
                "fid" => $fid
            ])) {
                if ($weSql->select("forum", "fid=${fid}")['state'] == 0) {
                    if ($weSql->update("forum", [
                        "state" => 1
                    ], "fid=${fid}")) {
                        $code = 1;
                        $msg = "审核成功";
                        $exception = "审核成功";
                    } else {
                        $code = -1;
                        $msg = "审核失败";
                        $exception = "审核失败";
                    }
                } else {
                    $code = -1;
                    $msg = "贴子无法审核";
                    $exception = "审核失败";
                }
            }else{
                $code = -1;
                $msg = "贴子不存在";
                $exception = "审核失败";
            }
        }else{
            $code = -1;
            $msg = "账号权限过低";
            $exception = "需要管理员及以上的权限";
        }
    }else{
        $code = -1;
        $msg = "账号密码错误";
        $exception = "账号密码错误";
    }

}

/** @var $code
 * @var $msg
 * @var $exception
 */
@$result = [
    'code' => $code,
    'msg' => $msg,
    'exception' => $exception
];
echo json_encode($result,JSON_UNESCAPED_UNICODE);

?>